package com.huawei.hianalytics.f.g;

import android.text.TextUtils;
import android.util.Pair;
import com.huawei.hianalytics.f.b.c;
import com.huawei.hianalytics.g.b;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import org.json.JSONObject;

public abstract class j {
    public static long a(String str, long j) {
        long j2 = 0;
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(str, Locale.getDefault());
            j2 = simpleDateFormat.parse(simpleDateFormat.format(Long.valueOf(j))).getTime();
        } catch (ParseException e) {
            b.c("HiAnalytics/event/stringUtil", "getMillisOfDate(): Time conversion Exception !");
        }
        return j2;
    }

    public static Pair<String, String> a(String str) {
        if ("_default_config_tag".equals(str)) {
            return new Pair(str, "");
        }
        Object obj;
        Object substring;
        String[] split = str.split("-");
        if (split.length > 2) {
            obj = split[split.length - 1];
            substring = str.substring(0, (str.length() - obj.length()) - 1);
        } else {
            substring = split[0];
            obj = split[1];
        }
        return new Pair(substring, obj);
    }

    public static String a() {
        return "f6040d0e807aaec325ecf44823765544e92905158169f694b282bf17388632cf95a83bae7d2d235c1f039";
    }

    public static String a(int i) {
        switch (i) {
            case 0:
                return "oper";
            case 1:
                return "maint";
            case 2:
                return "preins";
            case 3:
                return "diffprivacy";
            default:
                return "allType";
        }
    }

    public static String a(String str, int i) {
        if (!TextUtils.isEmpty(str) && str.length() > i) {
            int length = str.length();
            for (int i2 = 0; i2 < i; i2++) {
                str = str.substring(length - 1) + str.substring(0, length - 1);
            }
        }
        return str;
    }

    public static String a(String str, String str2, String str3) {
        return "_default_config_tag".equals(str) ? "_default_config_tag#" + str3 : str + "-" + str2 + "#" + str3;
    }

    public static String a(String str, String str2, String str3, String str4, String str5) {
        byte[] a = f.a(str);
        byte[] a2 = f.a(str2);
        byte[] a3 = f.a(str3);
        byte[] a4 = f.a(str4);
        int length = a.length;
        if (length > a2.length) {
            length = a2.length;
        }
        if (length > a3.length) {
            length = a3.length;
        }
        if (length > a4.length) {
            length = a4.length;
        }
        char[] cArr = new char[length];
        for (int i = 0; i < length; i++) {
            cArr[i] = (char) (((a[i] ^ a2[i]) ^ a3[i]) ^ a4[i]);
        }
        return a(cArr, f.a(str5));
    }

    public static String a(Map<String, String> map, Map<String, String> map2) {
        if (map == null && map2 == null) {
            b.c("HiAnalytics/event/stringUtil", "evtHeaderEx and evtCommonEx is null,");
            return "";
        }
        JSONObject jSONObject;
        JSONObject jSONObject2 = new JSONObject();
        if (map != null && map.size() > 0) {
            jSONObject = new JSONObject();
            for (Entry entry : map.entrySet()) {
                jSONObject.put((String) entry.getKey(), entry.getValue());
            }
            jSONObject2.put("headerEx", jSONObject);
        }
        if (map2 != null && map2.size() > 0) {
            jSONObject = new JSONObject();
            for (Entry entry2 : map2.entrySet()) {
                jSONObject.put((String) entry2.getKey(), entry2.getValue());
            }
            jSONObject2.put("commonEx", jSONObject);
        }
        if (jSONObject2.length() != 0) {
            return jSONObject2.toString();
        }
        b.c("HiAnalytics/event/stringUtil", "evtHeaderEx/evtCommonEx is empty,");
        return "";
    }

    private static String a(char[] cArr, byte[] bArr) {
        try {
            return f.a(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(cArr, bArr, 10000, DnsConfig.MAX_CACHE_ENTRIES)).getEncoded());
        } catch (InvalidKeySpecException e) {
            b.d("HiAnalytics/event/stringUtil", "getAuthToken() encryptPBKDF2 Invalid key specification !");
            return null;
        } catch (NoSuchAlgorithmException e2) {
            b.d("HiAnalytics/event/stringUtil", "getAuthToken() encryptPBKDF2 No such algorithm!");
            return null;
        }
    }

    public static String[] a(List<String> list, String str) {
        List arrayList = new ArrayList();
        for (String replace : list) {
            arrayList.add(str.replace("{url}", replace));
        }
        return (String[]) arrayList.toArray(new String[arrayList.size()]);
    }

    public static void b(Map<String, Map<String, List<c>>> map, Map<String, Map<String, List<c>>> map2) {
        for (Entry entry : map.entrySet()) {
            String str = (String) entry.getKey();
            Map map3 = (Map) entry.getValue();
            Map map4 = (Map) map2.get(str);
            if (map4 == null) {
                map2.put(str, map3);
            } else {
                for (Entry entry2 : map3.entrySet()) {
                    str = (String) entry2.getKey();
                    List list = (List) entry2.getValue();
                    List list2 = (List) map4.get(str);
                    if (list2 != null) {
                        list2.addAll(list);
                    } else {
                        map4.put(str, list);
                    }
                }
            }
        }
    }
}
